//
//  WaterFlowDisplayInfo.m
//  WaterfallFlowDemo
//
//  Created by Lining on 15/5/3.
//  Copyright (c) 2015年 Lining. All rights reserved.
//

#import "WaterFlowDisplayInfo.h"


@implementation WaterFlowDisplayInfo
static CGFloat cellWidth = 0;

+ (void)setWidth:(CGFloat)width
{
	cellWidth = width;
}

- (instancetype)initWithAbstract:(TipAbstract *)abstract
{
    self = [super init];
    if (self)
    {
		
		cellWidth = ([UIScreen mainScreen].bounds.size.width -30 )/2;
		self.toolBarHeight = 20;
        self.abstract = abstract;
		self.imageHeight = cellWidth/[self.abstract.originalFirstPictureWidth integerValue] *[self.abstract.originalFirstPictureHeight integerValue] ;
		self.titleHeight = [self neededWidthForText:abstract.title];
		self.h = self.imageHeight  + kControlInterval +  self.titleHeight + kControlInterval + self.toolBarHeight +kControlInterval + 1 + kControlInterval + kUserHeaderSize + kControlInterval;

    }

    return self;
}

- (NSInteger)w
{
	return cellWidth;
}

- (CGFloat)neededWidthForText:(NSString *)text 
{
	CGSize stringSize;
	stringSize = [text sizeWithFont:self.titleFont
				  constrainedToSize:CGSizeMake(self.w - 12*2, 1000)];
	return roundf(stringSize.height);
}

- (CGFloat)randomHehght
{
    return arc4random()%100 + 200;
}

- (UIFont *)titleFont
{
	if (!_titleFont)
	{
		_titleFont = [UIFont systemFontOfSize:14];
	}
	return _titleFont;
}

+ (instancetype)infoWithAbstract:(TipAbstract *)abstract
{
    return [[self alloc] initWithAbstract:abstract];
}


- (NSString *)img
{
    return _abstract.thumbnail;
}


- (NSString *)price
{
    return _abstract.title;
}
@end
